/**
 *
 */
public class ShellSort {
    //gap->分组数；gap=n/2；gap=gap/2；
    public static void shellSort(int[] array){
        int gap = array.length/2;//10
        while (gap >=1) {
            shell(array,gap);
            gap /= 2;
        }

    }

    public static void shell(int[] array,int gap) {
        //类直接插入排序
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i-gap;
            for (; j >= 0; j-=gap) {
                //>=
                if(array[j] > tmp) {
                    array[j+gap] = array[j];
                }else {
                    //array[j+1] = tmp;
                    break;//
                }
            }
            array[j+gap] = tmp;
        }
    }

    public static void main(String[] args) {
        int[] arr={9,8,7,6,10,5,4,3,2,1};
        shellSort(arr);
        for (int x :
                arr) {
            System.out.println(x);
        }

    }
}
